package com.vn.ducktohome.screen;

import com.badlogic.gdx.scenes.scene2d.actions.AlphaAction;
import com.badlogic.gdx.scenes.scene2d.actions.DelayAction;
import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
import com.badlogic.gdx.scenes.scene2d.actions.ParallelAction;
import com.badlogic.gdx.scenes.scene2d.actions.ScaleToAction;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.vn.ducktohome.enums.ScreenEnum;
import com.vn.ducktohome.gamelogic.GameControl;
import com.vn.ducktohome.helper.SoundMusic;
import com.vn.ducktohome.screen.play.Lake;
import com.vn.ducktohome.screen.play.LeftPanel;

public class PlayScreen extends BaseScreen {
	private LeftPanel leftPanel;
	private Lake lake;
	private static PlayScreen install;
	private static Image imgTemp;
	private SoundMusic soundMusic;

	@Override
	public void show() {
		super.show();
		install = this;
		Image bg = new Image(GameControl.getAtlas().findRegion("play/background"));
		leftPanel = new LeftPanel();
		lake = new Lake();
		imgTemp = null;
		stage.addActor(bg);
		stage.addActor(leftPanel);
		stage.addActor(lake);
		soundMusic = new SoundMusic();
		soundMusic.setX(16);
		soundMusic.setY(45);
		stage.addActor(soundMusic);
	}
	
	public static void duckWin(){
		Image imgDuckWin = new Image(GameControl.getAtlas().findRegion("select_level/duck-win"));
		imgDuckWin.setX(Lake.X + Lake.X_CENTER);
		imgDuckWin.setY(Lake.Y_CENTER);
		imgDuckWin.setScale(0);
		install.stage.addActor(imgDuckWin);
		AlphaAction alpha1 = new AlphaAction();
		alpha1.setAlpha(0f);
		alpha1.setDuration(0f);
		
		AlphaAction alpha2 = new AlphaAction();
		alpha2.setAlpha(1f);
		alpha2.setDuration(1f);
		
		MoveToAction moveTo = new MoveToAction();
		moveTo.setPosition(0, 0);
		moveTo.setDuration(1);
		
		ScaleToAction scaleTo = new ScaleToAction();
		scaleTo.setScale(1);
		scaleTo.setDuration(1);
		
		ParallelAction parallel = new ParallelAction();
		parallel.addAction(alpha2);
		parallel.addAction(moveTo);
		parallel.addAction(scaleTo);
		
		DelayAction delay = new DelayAction();
		delay.setDuration(1f);
		SequenceAction sequence = new SequenceAction();
		sequence.addAction(alpha1);
		sequence.addAction(parallel);
		sequence.addAction(delay);
		imgDuckWin.addAction(sequence);
		imgTemp = imgDuckWin;
	}
	
	public static void duckLose(){
		Image imgDuckLose = new Image(GameControl.getAtlas().findRegion("select_level/duck-lose"));
		imgDuckLose.setY(480);
		install.stage.addActor(imgDuckLose);
		MoveToAction moveTo = new MoveToAction();
		moveTo.setY(0);
		moveTo.setDuration(0.5f);
		DelayAction delay = new DelayAction();
		delay.setDuration(2f);
		SequenceAction sequence = new SequenceAction();
		sequence.addAction(moveTo);
		sequence.addAction(delay);
		imgDuckLose.addAction(sequence);
		imgTemp = imgDuckLose;
	}
	

	@Override
	public void render(float arg0) {
		super.render(arg0);
		if (imgTemp != null)
			if (imgTemp.getActions().size == 0){
				imgTemp = null;
				GameControl.getScreenManager().createScreen(ScreenEnum.SELECT_LEVEL_SCREEN);
				GameControl.getScreenManager().getScreen().show();
			}
	}

	@Override
	public void dispose() {
		super.dispose();
	}
}
